编译环境:

  • 操作系统:Windows 10
  • 编译器:Microsoft Visual Studio Enterprise 2017 Version 15.9.41

注意事项:

  • 建议Windows 10 在 时间和语言–>语言和区域–>语言 设置为英文,在 时间和语言–>语言和区域–>区域设置为美国避免一些奇怪的错误。
  • VS建议升级最新版本,之前遇到由于VS版本低导致各种编译错误,升级VS后成功编译。
  • 如果QT源码,需要解压,建议安装最新WinRar 防止解压出错。之前遇到因为WinRar版本问题而发生解压错误。

#####下面还需要一些准备工作:
1. 安装python2.7.18,并检查在Windos系统【环境变量】path中对应的路径设置
然后在widnows cmd中输入:python –version

1
Python 2.7.18

检测安装的版本号,以及是否安装成功。
2. 安装安装ruby,并检查在Windos系统【环境变量】path中对应的路径设置
然后在widnows cmd中输入:ruby –version

1
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [i386-mingw32]

3. 安装安装perl,并检查在Windos系统【环境变量】path中对应的路径设置
然后在widnows cmd中输入:perl –version

1
This is perl 5, version 32, subversion 0 (v5.32.0) built for MSWin32-x64-multi-thread

4. 编译oepnssl,编译qt需要用到
oepnssl源码地址:https://github.com/openssl/openssl
编译之前找到configdata.pm和makefile两个文件, 用记事本打开, 搜索 “/MD” 字符串, 替换成 “/MT”,编译选项修改MT
编译配置项:

1
perl Configure VC-WIN32 shared no-asm --prefix="g:\SDK\OpenSSL\openssl-1.1.1" --openssldir="g:\SDK\OpenSSL\ssl"

参数说明:
–prefix是Openssl编译完后的安装路径。
–openssldir是Openssl编译完后的生成的配置文件的安装路径。

1
2
3
a. 打开VS2017中的vcvars32.bat
b. 然后输入 nmake 开始编译。
c. 输入 nmake install 归档头文件等到安装路径

5. 下载depot_tools,下载地址:https://chromium.googlesource.com/chromium/tools/depot_tools.git
并在Windos系统【环境变量】path中设置对应的路径。

1
如:D:\SDK\depot_tools


终于可以开始编译QT了
QT5.15.1源码下载:https://download.qt.io/archive/qt/5.15/5.15.1/single/
Windows编译配置项:

1
configure -opensource -platform win32-msvc2017 -developer-build -mp -debug-and-release -force-debug-info -v -confirm-license OPENSSL_PREFIX=D:\SDK\oepnssl\1.1.1g\debug_md -openssl-linked -I  D:\SDK\oepnssl\1.1.1g\debug_md\include -L D:\SDK\oepnssl\1.1.1g\debug_md\lib OPENSSL_LIBS="libssl.lib libcrypto.lib Ws2_32.lib  Gdi32.lib Advapi32.lib Crypt32.lib User32.lib" -webengine-proprietary-codecs -prefix D:\SDK\build\qt5.15.1

MacOS编译配置项:

1
./configure -opensource -platform macx-clang -developer-build -debug-and-release -force-debug-info -v -confirm-license -skip qtwebengine -prefix ~/SDK/QT/5.15.1/macos

IOS编译配置项:

1
./configure -opensource -xplatform macx-ios-clang -developer-build -debug-and-release -force-debug-info -confirm-license -nomake examples -nomake tests -skip qtwebengine -prefix ~/SDK/QT/5.15.1/ios

1
2
3
a. 打开VS2017中的 x64_x86 Cross Tools Command Prompt for VS 2017
b. 输入nmake
c. 输入nmake install
1
2
3
4
mac和ios都下面命令:
a. 打开终端,进入到源码目录
b. 输入make 或者 make -j20(j20表示用20个线程构建,加快构建速度,最大线程数可以参考cpu的线程数)
c. 输入make install

注意:如果需要重新编译可以删除

1
2
3
config.cache
.qmake.cache
config.tests

重新开始编译。


#####参考文章
Qt for Windows - Building from Source:
https://doc.qt.io/qt-5/windows-building.html
Qt for Windows - Requirements:
https://doc.qt.io/qt-5/windows-requirements.html
Qt for Windows:
https://doc.qt.io/qt-5/windows.html


 评论